package com.iemes.controller.inventory;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.inventory.MxFormMap;
import com.iemes.entity.inventory.PisFormMap;
import com.iemes.entity.inventory.StockFormMap;
import com.iemes.mapper.inventory.MxMapper;
import com.iemes.mapper.inventory.PutInStorageMapper;
import com.iemes.util.Common;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.inject.Inject;
import java.util.List;

@Controller
@RequestMapping("/mx/")
public class MxController extends BaseController {
    @Inject
    private MxMapper mxMapper;

    @RequestMapping("mxIndex")
    public String index(Model model){
//        String[] btnArray = new String[]{"<button type=\"button\" id=\"addAccount\" class=\"btn btn-primary marR10\">新增</button>", "<button type=\"button\" id=\"editAccount\" class=\"btn btn-info marR10\">编辑</button>", "<button type=\"button\" id=\"delAccount\" class=\"btn btn-danger marR10\">删除</button>"};
//        model.addAttribute("res", findByRes());
//        model.addAttribute("btn", btnArray);
        return Common.BACKGROUND_PATH + "/inventory/mx/mxIndex";
    }

    @ResponseBody
    @RequestMapping("getPisPage")
    public PageInfo getWorkOrderPage(){
        PageHelper.startPage(1, 10);
        List<MxFormMap> schedulingFormMaps = mxMapper.getMxPage();
        PageInfo pageInfo = new PageInfo<>(schedulingFormMaps);
        return pageInfo;
    }


    @RequestMapping("stockIndex")
    public String StockIndex(Model model){
//        String[] btnArray = new String[]{"<button type=\"button\" id=\"addAccount\" class=\"btn btn-primary marR10\">新增</button>", "<button type=\"button\" id=\"editAccount\" class=\"btn btn-info marR10\">编辑</button>", "<button type=\"button\" id=\"delAccount\" class=\"btn btn-danger marR10\">删除</button>"};
//        model.addAttribute("res", findByRes());
//        model.addAttribute("btn", btnArray);
        return Common.BACKGROUND_PATH + "/inventory/mx/stockIndex";
    }


    @ResponseBody
    @RequestMapping("getStockPage")
    public PageInfo getStockPage(){
        PageHelper.startPage(1, 10);
        List<StockFormMap> schedulingFormMaps = mxMapper.getStockPage();
        for (StockFormMap st : schedulingFormMaps){
            if(st.get("warm").toString().equals("0")){
                st.set("warm","否");
            }else {
                st.set("warm","是");
            }
        }
        PageInfo pageInfo = new PageInfo<>(schedulingFormMaps);
        return pageInfo;
    }

}
